home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / asmutil / asm_n_z.zip / SEND.ASM < prev    next >
Assembly Source File  |  1986-07-14  |  15KB  |  354 lines

  1.         Page    55,132
  2.         Title   SEND - Send a file using XMODEM protocol
  3.  
  4. SPECIAL Equ     0                       ;If true, include data size in block
  5.  
  6.         If      SPECIAL
  7. BLOCK   Struc
  8. B_SOH   Db      001H                    ;Start of header
  9. B_BLK1  Db      000H                    ;Block number
  10. B_BLK2  Db      0FFH                    ;(Block number)'
  11. B_CNT   Db      ?                       ;Count of bytes used in the data area
  12. B_DATA  Db      128 Dup (?)             ;The data area
  13. B_CHKSUM Db     ?                       ;Checksum of the data
  14. BLOCK   Ends
  15.         Else
  16. BLOCK   Struc
  17. B_SOH   Db      001H                    ;Start of header
  18. B_BLK1  Db      000H                    ;Block number
  19. B_BLK2  Db      0FFH                    ;(Block number)'
  20. B_DATA  Db      128 Dup (?)             ;The data area
  21. B_CHKSUM Db     ?                       ;Checksum of the data
  22. BLOCK   Ends
  23.         Endif
  24.  
  25. ERROR   Macro   N
  26.         Mov     AH,09H                  ;Display the error message
  27.         Lea     DX,ERRMSG&N             ;
  28.         Int     021H                    ;
  29.         Mov     AX,04C10H+N             ;And leave
  30.         Int     021H                    ;
  31.         Endm
  32.  
  33. CODE    Segment Public  'CODE'
  34. CODE    Ends
  35.  
  36. DATA    Segment Public  'DATA'
  37.  
  38. BAUD_TABLE Label Word
  39.         Dw      9600                    ;
  40.         Dw      4800                    ;
  41.         Dw      2400                    ;
  42.         Dw      1200                    ;
  43.         Dw      600                     ;
  44.         Dw      300                     ;
  45.         Dw      150                     ;
  46.         Dw      110                     ;
  47.  
  48. FILENAME Db     64 Dup (0)              ;Name of file to send
  49.  
  50. BUFFER  BLOCK   <>                      ;The block buffer
  51.  
  52. ERRMSG0 Db      '?No input file specified',13,10,'$'
  53. ERRMSG1 Db      '?Unable to open input file',13,10,'$'
  54. ERRMSG2 Db      '?Invalid baud rate specified',13,10,'$'
  55. ERRMSG3 Db      '?Receiver time-out occurred',13,10,'$'
  56. ERRMSG4 Db      '?Error while reading the input file',13,10,'$'
  57. ERRMSG5 Db      '^C',13,10,'%Transmission aborted via control-C',13,10,'$'
  58.  
  59. TXTMSG1 Db      'Waiting for receiver...',13,10,'$'
  60. TXTMSG2 Db      'Block number '
  61. TXTNUM2 Db      '0    ',13,'$'
  62. TXTMSG3 Db      10,'Transmission complete',13,10,'$'
  63. TXTMSG4 Db      'No retries needed',13,10,'$'
  64. TXTMSG5 Db      'Retry count was '
  65. TXTNUM5 Db      '0    ',13,10,'$'
  66.  
  67. MODE    Db      11101011B               ;9600 baud, odd parity, 1 stop bit,
  68.                                         ;8 bit character
  69.  
  70. BLOCK_COUNT Dw  0                       ;Total block count
  71. RETRY_COUNT Dw  0                       ;Retry count
  72.  
  73. DATA    Ends
  74.  
  75. STACK   Segment Stack   'STACK'
  76.  
  77.         Dw      128 Dup (?)             ;Program stack
  78.  
  79. STACK   Ends
  80.  
  81. CODE    Segment Public  'CODE'
  82.  
  83.         Assume  CS:CODE,DS:Nothing,ES:Nothing,SS:STACK
  84.  
  85. MAIN    Proc    Near
  86.         Sti                             ;Enable interrupts
  87.         Mov     AX,DATA                 ;Set up ES
  88.         Mov     ES,AX                   ;
  89.  
  90.         Assume  ES:DATA
  91.  
  92.         Cld                             ;Make sure the direction flag is clear
  93.         Mov     SI,080H                 ;Use SI to get the file name
  94.         Lodsb                           ;Get the length
  95.         Or      AL,AL                   ;Is there anything??
  96.         Jnz     MAIN01                  ;Yes. Proceed
  97. MAIN00: Mov     AX,ES                   ;Set up DS
  98.         Mov     DS,AX                   ;
  99.  
  100.         Assume  DS:DATA
  101.  
  102.         ERROR   0                       ;Nope. Die!
  103.  
  104.         Assume  DS:Nothing
  105.  
  106. MAIN01: Cbw                             ;Make it a word count
  107.         Mov     CX,AX                   ;Copy to CX
  108.  
  109. MAIN05: Jcxz    MAIN00                  ;If nothing left, error!
  110.         Dec     CX                      ;Decrement the character count
  111.         Lodsb                           ;And get the character
  112.         Cmp     AL,020H                 ;Space or less??
  113.         Ja      MAIN10                  ;Nope. Start the file name
  114.         Jmp Short MAIN05                ;Try again...
  115.  
  116. MAIN10: Lea     DI,FILENAME             ;Point DI to the file name buffer
  117. MAIN11: Stosb                           ;Store the character
  118.         Jcxz    MAIN20                  ;Got the file name. Open the file
  119.         Dec     CX                      ;Decrement the character count
  120.         Lodsb                           ;Get the next character
  121.         Cmp     AL,020H                 ;Is it a displayable character
  122.         Ja      MAIN11                  ;Yes. Put it in the file name
  123.  
  124. MAIN13: Jcxz    MAIN20                  ;No more characters?
  125.         Dec     CX                      ;Decrement the count
  126.         Lodsb                           ;Get another character
  127.         Cmp     AL,020H                 ;Space or less??
  128.         Ja      MAIN15                  ;Yes. See if it's a number
  129.         Jmp Short MAIN13                ;Keep looking
  130.  
  131. MAIN15: Xor     DX,DX                   ;Clear DX
  132. MAIN16: Cmp     AL,'0'                  ;Is this a digit??
  133.         Jae     MAIN18                  ;Yes.
  134. MAIN17: ERROR   2                       ;Not a valid baud rate
  135.  
  136. MAIN18: Cmp     AL,'9'                  ;Still a digit??
  137.         Ja      MAIN17                  ;Nope.
  138.         Sub     AL,'0'                  ;Convert to binary
  139.         Cbw                             ;Convert to a word
  140.         Shl     DX,1                    ;Double the previous number
  141.         Mov     BX,DX                   ;Save in BX for a bit
  142.         Shl     DX,1                    ;
  143.         Shl     DX,1                    ;
  144.         Add     DX,BX                   ;Now DX = (Old DX)*10
  145.         Add     DX,AX                   ;Add in the last digit
  146.         Jcxz    MAIN19                  ;All done.
  147.         Dec     CX                      ;Decrement the character count
  148.         Lodsb                           ;And get a character
  149.         Cmp     AL,020H                 ;Space or less?
  150.         Ja      MAIN16                  ;
  151.  
  152. MAIN19: Mov     AX,DX                   ;Put the baud rate in AX
  153.         Lea     DI,BAUD_TABLE           ;Point to the baud rate table
  154.         Mov     CX,8                    ;Eight entries in the table
  155.         Repne Scasw                     ;Look for this baud rate
  156.         Jne     MAIN17                  ;No good! Die!
  157.         Mov     AL,CL                   ;Get the index
  158.         Mov     CL,5                    ;And position it
  159.         Shl     AL,CL                   ;
  160.         Or      AL,00001011B            ;Odd parity, 1 stop bit, 8 bit character
  161.         Mov     MODE,AL                 ;And save it
  162.  
  163. MAIN20: Mov     AX,ES                   ;Set up DS
  164.         Mov     DS,AX                   ;
  165.  
  166.         Assume  DS:DATA
  167.  
  168.         Mov     AX,03D00H               ;Open the file for read-only
  169.         Lea     DX,FILENAME             ;
  170.         Int     021H                    ;
  171.         Jnc     MAIN25                  ;Proceed!
  172.         ERROR   1                       ;File not found!
  173.  
  174. MAIN25: Mov     BX,AX                   ;Put the handle in BX
  175.  
  176.         Xor     AH,AH                   ;Initialize the RS232 channel
  177.         Mov     AL,MODE                 ;
  178.         Xor     DX,DX                   ;On channel zero
  179.         Int     014H                    ;
  180.  
  181.         Mov     AH,09H                  ;Display the "Waiting..." message
  182.         Lea     DX,TXTMSG1              ;
  183.         Int     021H                    ;
  184.  
  185.         Mov     CX,64                   ;This shall be our original timeout
  186. MAIN30: Mov     AH,06H                  ;See if a character is waiting
  187.         Mov     DL,0FFH                 ;
  188.         Int     021H                    ;
  189.         Jz      MAIN32                  ;Nope.
  190.         Cmp     AL,3                    ;Is it a control-C??
  191.         Jne     MAIN32                  ;
  192.  
  193.         Mov     AH,03EH                 ;Close the input file
  194.         Int     021H                    ;
  195.         ERROR   5                       ;And die
  196.  
  197. MAIN32: Mov     AH,02H                  ;Get a character from the s